package com.base.device.controller;

import java.util.List;
import java.util.Arrays;

import com.base.device.domain.bo.TSysDeviceCertBo;
import com.base.device.domain.vo.TSysDeviceCertVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.base.common.annotation.RepeatSubmit;
import com.base.common.annotation.Log;
import com.base.common.core.controller.BaseController;
import com.base.common.core.domain.PageQuery;
import com.base.common.core.domain.R;
import com.base.common.core.validate.AddGroup;
import com.base.common.core.validate.EditGroup;
import com.base.common.enums.BusinessType;
import com.base.common.utils.poi.ExcelUtil;
import com.base.device.service.ITSysDeviceCertService;
import com.base.common.core.page.TableDataInfo;

/**
 * 系统设备证书
 *
 * @author base
 * @date 2023-10-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/device/sysDeviceCert")
public class TSysDeviceCertController extends BaseController {

    private final ITSysDeviceCertService iTSysDeviceCertService;

    /**
     * 查询系统设备证书列表
     */
// @SaCheckPermission("device:sysDeviceCert:list")
    @GetMapping("/list")
    public R<TableDataInfo<TSysDeviceCertVo>> list(TSysDeviceCertBo bo, PageQuery pageQuery) {
        return R.ok(iTSysDeviceCertService.queryPageList(bo, pageQuery));
    }

    /**
     * 导出系统设备证书列表
     */
    //   @SaCheckPermission("device:sysDeviceCert:export")
    @Log(title = "系统设备证书", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TSysDeviceCertBo bo, HttpServletResponse response) {
        List<TSysDeviceCertVo> list = iTSysDeviceCertService.queryList(bo);
        ExcelUtil.exportExcel(list, "系统设备证书", TSysDeviceCertVo.class, response);
    }

    /**
     * 获取系统设备证书详细信息
     *
     * @param autoId 主键
     */
    //    @SaCheckPermission("device:sysDeviceCert:query")
    @GetMapping("/{autoId}")
    public R<TSysDeviceCertVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String autoId) {
        return R.ok(iTSysDeviceCertService.queryById(autoId));
    }

    /**
     * 新增系统设备证书
     */
//     @SaCheckPermission("device:sysDeviceCert:add")
    @Log(title = "系统设备证书", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TSysDeviceCertBo bo) {
        return toAjax(iTSysDeviceCertService.insertByBo(bo));
    }

    /**
     * 修改系统设备证书
     */
    //   @SaCheckPermission("device:sysDeviceCert:edit")
    @Log(title = "系统设备证书", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TSysDeviceCertBo bo) {
        return toAjax(iTSysDeviceCertService.updateByBo(bo));
    }

    /**
     * 删除系统设备证书
     *
     * @param autoIds 主键串
     */
    //  @SaCheckPermission("device:sysDeviceCert:remove")
    @Log(title = "系统设备证书", businessType = BusinessType.DELETE)
    @DeleteMapping("/{autoIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] autoIds) {
        return toAjax(iTSysDeviceCertService.deleteWithValidByIds(Arrays.asList(autoIds), true));
    }
}
